package leetcode;


import java.util.HashSet;
import java.util.Set;

/**
 * 零矩阵
 */
public class LeetCode_0108 {
    public void setZeroes(int[][] matrix) {
        Set<Integer> xSet = new HashSet<>();
        Set<Integer> ySet = new HashSet<>();
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                if (matrix[i][j] == 0) {
                    xSet.add(i);
                    ySet.add(j);
                }
            }
        }
        for (Integer x : xSet) {
            for (int j = 0; j < matrix[x].length; j++) matrix[x][j] = 0;
        }

        for (Integer y : ySet) {
            for (int i = 0; i < matrix.length; i++) matrix[i][y] = 0;
        }
    }
}